package net.rvb1.gwt.grad.ui.client.events;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

/**
 * Represents a {@link GwtEvent} which can be canceled.<BR/>
 * Subclasses should override {@link #onCancel()} if you want to do something special when such an
 * event is canceled.
 * 
 * @param <H> handler type
 */
public abstract class CancelableGwtEvent<H extends EventHandler> extends GwtEvent<H> {

  private boolean canceled;

  /**
   * Cancels the event.
   * 
   */
  public final void cancel() {
    this.canceled = true;
    onCancel();
  }

  /**
   * Has the event been canceled by a handler ?
   * 
   * @return <code>true</code> id the event has been canceled, <code>false</code> otherwise.
   */
  public boolean isCanceled() {
    return canceled;
  }

  /**
   * Callback called when an event is canceled.
   * 
   * @see #cancel()
   */
  protected void onCancel() {
  }

}